﻿@model IEnumerable<DemoPlena.Dominio.Usuario>

@{
    ViewBag.Title = "Lista";
}

<h2>Lista</h2>

@*<p>*@
@*    @Html.ActionLink("Create New", "Create")*@
@*</p>*@


<script type="text/javascript">
    $(function() {
        $('#busca').autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: '@Url.Action("Busca")',
                    dataType: "json",
                    contentType: 'application/json, charset=utf-8',
                    data: {
                        termo: $("#busca").val()

                    },
                    success: function(data) {
                        response($.map(data, function (item) {
                            return {
                                id: item.IdUsuario,
                                label: item.value
                                //value: item.value
                               
                            };
                        }));
                       
                    },
                    error: function(xhr, status, error) {
                        alert(error);
                    },
                });
            },
            
           select: function (ui,i) {
                //var valor = $("#busca").val();
               // alert(i.item.value);
               $("#tabela1").empty();
               $("#tabela1").load('BuscaUsuarioUnico?id=' + i.item.id);
           },
           minLength: 1
        });

    });


</script>
<form >
    <label for="busca">Busca</label>
    <!--<input type="hidden" value="" name="id" id="idusuario" />-->
    <input type="text" id="busca" name="busca"/>
</form>

<table id="tabela1">
    <tr>
          <th>
            @Html.DisplayNameFor(model => model.IdUsuario)
        </th>    
        <th>
            @Html.DisplayNameFor(model => model.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Email)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Senha)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TipoUsuario)
        </th>
        <th>Editar</th>
        <th>Deletar</th>
    </tr>

@foreach (var item in Model) {
    <tr>
        
         <td>
            @Html.DisplayFor(modelItem => item.IdUsuario)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Nome)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Senha)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TipoUsuario)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.IdUsuario })
            @*        @Html.ActionLink("Details", "Details", new { id=item.IdUsuario }) |*@
        </td>
        <td>@Html.ActionLink("Delete", "Delete", new { id=item.IdUsuario })</td>
    </tr>
}

</table>
